<div class="amp-content">
  <h3 class="amp-header"><?php echo $action_title; ?></h3>

  <div class="amp-content">
    <?php if (! empty($filters)) { ?>
    <form action="<?php echo Simplify::response()->makeUrl($form->buildRoute()) ?>" method="get">
      <span>
        <?php foreach ($filters as $filter) { ?>
        <?php echo $filter->render() ?>
        <?php } ?>

        <input type="submit" value="Ok"/>
      </span>
    </form>
    <?php } ?>

    <form action="<?php echo Simplify::response()->makeUrl(Simplify::request()->route(), array('action' => 'bulk')) ?>" method="post" class="wrapper">
      
      <span class="amp-toolbar-container">
        <ul class="amp-toolbar">
          <?php if (! empty($pager)) { ?>
            <?php echo $this->pager->show($pager); ?>
          <?php } ?>
        </ul>
      </span>
      
      <table class="amp-table wrapped">
        <tr>
          <th style="width: 1%;"></th>

          <?php while ($element = $elements->next()) { ?>
          <th><?php echo $element->getTitle() ?></th>
          <?php } ?>

          <th>Actions</th>
        </tr>

        <?php while ($obj = $data->next()) { ?>
        <tr class="<?php echo $this->cycle->next('default', array('odd', 'even')) ?>">
          <td><input type="checkbox" class="row-check" name="<?php echo $pk ?>[]" value="<?php echo $obj->$pk ?>"/></td>

          <?php $elements->reset(); ?>

          <?php while ($element = $elements->next()) { ?>
          <td><?php echo $element->render($obj, $action) ?></td>
          <?php } ?>

          <td style="text-align: center;">
            <a href="<?php echo Simplify::response()->makeUrl(Simplify::request()->route(), array('action' => 'view', $pk => $obj->$pk)) ?>"><?php echo $this->icon->show('view') ?></a>
            <a href="<?php echo Simplify::response()->makeUrl(Simplify::request()->route(), array('action' => 'edit', $pk => $obj->$pk)) ?>"><?php echo $this->icon->show('edit') ?></a>
            <a href="<?php echo Simplify::response()->makeUrl(Simplify::request()->route(), array('action' => 'delete', $pk => $obj->$pk, 'confirm' => 1)) ?>"
              onclick="return confirm('Confirma a remoção deste registro?');"><?php echo $this->icon->show('remove') ?></a>
          </td>
        </tr>
        <?php } ?>
      </table>

      <span class="amp-toolbar-container">
        <ul class="amp-toolbar">
          <li class="amp-toolbar-item">
            <select name="bulk_action">
              <option value="">Bulk actions</option>
              <option value="view">View</option>
              <option value="delete">Delete</option>
            </select>
            <input type="submit" value="Ok"/>
          </li>

          <li class="amp-toolbar-item">
            Selecionar:
            <a href="javascript:" onclick="selectAll();"><?php echo $this->icon->show("select_all") ?></a>
            <a href="javascript:" onclick="selectNone();"><?php echo $this->icon->show("select_none") ?></a>
            <a href="javascript:" onclick="selectInvert();"><?php echo $this->icon->show("select_invert") ?></a>
          </li>

          <?php if (! empty($pager)) { ?>
              <?php echo $this->pager->show($pager); ?>
          <?php } ?>
        </ul>
      </span>
    </form>

    <script>
    function selectAll() {
      $('.row-check').attr('checked', 'checked');
    };

    function selectNone() {
      $('.row-check').removeAttr('checked');
    };

    function selectInvert() {
      var on = $('.row-check:checked');
      $('.row-check').attr('checked', 'checked');
      on.removeAttr('checked');
    };
    </script>
  </div>
</div>